package cn.ustb.dao;

import cn.ustb.entity.OptionalCourse;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface OptionalCourseDao {
    @Select("SELECT * FROM optionalCourse")
    List<OptionalCourse> getAll();

    @Select({"<script>",
            "select * from optionalCourse where courseId = #{courseId}",
            "<if test = \"yearTerm!=null\">"+
                    " and yearTerm =#{yearTerm}"+
                    " </if>",
            "</script>"
    })
    OptionalCourse get(@Param("courseId") String courseId, @Param("yearTerm") String yearTerm);

    @Insert("insert into optionalCourse values(#{yearTerm},#{courseId},#{courseName},#{credit},#{courseType},#{teacher},#{classWay},#{classTime})")
    void insert(OptionalCourse optionalCourse);

    @Update("update optionalCourse set YearTerm =#{yearTerm},CourseName =#{courseName}, Credit =#{credit},CourseType =#{courseType}, Teacher = #{teacher}, ClassWay =#{classWay}, ClassTime = #{classTime} where courseId =#{courseId}")
    void update(OptionalCourse optionalCourse);

    @Delete("delete from optionalCourse where courseId =#{courseId}")
    void delete(String courseId);

    @Select("SELECT * FROM optionalCourse where yearTerm =#{yearTerm}")
    List<OptionalCourse> getAllWithYearTerm(String yearTerm);
}
